<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>all</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		#searchForm div.ui-input-text {
			padding: 0.4em;
			display:inline-block;
		}
		#searchForm div.ui-input-button {
			padding: 0.4em;
			display:inline-block;
		}
	</style>
</head>
<body>
	<tags:breadcrumb name="breadcrumb" />
	<div class="icon-buttons">
		<input type="button" class="leave-page" data-inline="true" data-icon="back" data-iconpos="notext" value="返回"/>
	</div>
	<form:form id="detailForm" modelAttribute="" action="${ctx}/report/all/detail" method="post" data-ajax="false">
		<input type="hidden" id = "detailId" name="detailId">
		<input type="hidden" name="hasParent" value="true">
		<input type="hidden" id = "detailStart" name="startDate">
		<input type="hidden" id = "detailEnd" name="endDate">
	</form:form>
	<form:form id="searchForm" modelAttribute="" action="${ctx}/report/all/list" method="post" class="middleCls" data-ajax="false">
		<label>开始日期：</label>
		<input type="date" id="startDate" data-inline="true" name="startDate" value="${startDate}"/>
		<label>结束日期：</label>
		<input type="date" id="endDate" data-inline="true" name="endDate" value="${endDate}"/>
		<input data-inline="true" type="submit" value="查询"/>
	</form:form>
	<tags:message content="${message}"/>
	<div class="middleCls">提示：如果没有输入查询的开始和结束时间，默认显示最近7天的记录</div>
	<h3 class="middleCls">营业统计列表</h3>
	<c:if test="${not empty all}">
		<div class="form-input">
			<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
				<thead><tr><th>类别</th><th>总计</th></tr></thead>
				<tbody>
					<tr id="p">
						<td>产品销售</td>
						<td>${all.buyProduct}</td>
					</tr>
					<tr id="c">
						<td>手工护理</td>
						<td>${all.doCare}</td>
					</tr>
					<tr id="nr">
						<td>开卡和充值</td>
						<td>${all.newCard + all.rechargeCard}</td>
					</tr>
					<tr id="b">
						<td>员工提成</td>
						<td>${all.employeeBonus}</td>
					</tr>
					<tr id="s">
						<td>专家方案</td>
						<td>${all.solution}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</c:if>
	<script type="text/javascript">
		$(document).ready(function() {
		 	jQuery("#searchForm").validate({
		 		submitHandler: function(form){
					var startValue = $("#startDate").val();
					if (!startValue){
						showTip("开始日期必须填写!");
						return;
					}
					var endValue = $("#endDate").val();
					if (!endValue){
						showTip("结束日期必须填写!");
						return;
					}
					if(startValue && endValue){
						 var start = new Date(startValue.replace(/-/g, "/"));
						 var end = new Date(endValue.replace(/-/g, "/"));
						 if (end < start) {
							showTip("结束日期不能大于开始日期!");
							return;
						}
					 }
					 loading("正在提交，请稍等...");
					 form.submit();
				}
	        });
			$(".leave-page").click(function(){
				sessionStorage.removeItem("hasParent");
				window.location.href = "${ctx}";
			});
		 	$("#contentTable tbody tr").click(function(e){
				if (!this.id) {
					return;
				}
				sessionStorage.hasParent = "true";
				sessionStorage.reportStart = $("#startDate").val();
				sessionStorage.reportEnd = $("#endDate").val();
				$("#contentTable tbody tr").removeClass("select_active");
				$(this).addClass("select_active");
				reportDetail(this.id);
			});
		});
        function reportDetail(id){
            $("#detailId").val(id);
            $("#detailStart").val($("#startDate").val());
            $("#detailEnd").val($("#endDate").val());
        	$("#detailForm").submit();
        }
	</script>
</body>
</html>
